#!/usr/bin/env python
# -*- coding: UTF-8 -*-

r"""
lazyxml: a simple xml parse and generate lib.

@package
@copyright Copyright (c) 2012, lazyboy. inc
@license

example: see the demo
"""


__all__ = ['dump', 'dumps', 'load', 'loads']
__author__ = 'lazyboy <lazyboy.fan@gmail.com>'
__version__ = '1.1.0'


import utility
from core import LazyXML

def loads(content, cls=None, **kw):
    if not cls:
        cls = LazyXML(**kw)
    return cls.xml2dict(content)

def load(file, cls=None, **kw):
    content = utility.file_get_contents(file)
    if not cls:
        cls = LazyXML(**kw)
    return cls.xml2dict(content)

def dumps(obj, cls=None, **kw):
    if not cls:
        cls = LazyXML(**kw)
    return cls.dict2xml(obj)

def dump(obj, file, cls=None, **kw):
    if not cls:
        cls = LazyXML(**kw)
    tree = cls.dict2xml(obj)
    return utility.file_put_contents(file, tree)
